import React,{lazy,Suspense} from "react";
import {Navigate, Outlet, useRoutes} from "react-router-dom";
import Loading from "@/components/Loading";
import AuthComponent from "@/components/AuthComponent";
import {DatabaseOutlined, HomeOutlined,MedicineBoxOutlined} from "@ant-design/icons";


const lazyLoading = function (path:string){
    const Com = lazy(()=>import("@/pages/"+path))
    return <Suspense fallback={<Loading/>}>
                <Com/>
           </Suspense>
}
export const routes = [
        {
            path:"/",
            element:(
                <AuthComponent>
                    {lazyLoading("Index")}
                </AuthComponent>
            ),
            children:[
                {
                    label:"主页",
                    path:"/",
                    icon:<HomeOutlined />,
                    element:lazyLoading("Home")
                },
                {
                    label:"数据管理",
                    path:"/cmn",
                    icon: <DatabaseOutlined />,
                    element:<Outlet/>,
                    children:[
                        {
                            // index:true,
                            path: "/cmn",
                            isHide:true, //是否隐藏
                            element:<Navigate to={"dict"}/>
                        },{
                            // 数据字典
                            label:"数据字典",
                            path:"/cmn/dict",
                            element:lazyLoading("cmn/dict")
                        }
                    ]
                },
                {
                    label: "医院管理",
                    path: "/hospital",
                    icon:<MedicineBoxOutlined />,
                    element: <Outlet/>,
                    children: [
                        {
                            // index:true,
                            path:"/hospital",
                            isHide:true, //是否隐藏
                            element:<Navigate to={"hospitalSet"}/>
                        },{
                            // 医院设置
                            label:"医院设置",
                            path:"/hospital/hospitalSet",
                            element:lazyLoading("hospital/hospitalSet")
                        },{
                            // 医院列表
                            label:"医院列表",
                            path:"/hospital/hospitalList",
                            element:lazyLoading("hospital/hospitalList")
                        },{
                            //医院详情
                            label: "医院详情",
                            isHide: true,
                            path: "/hospital/show/:id",
                            element: lazyLoading("hospital/show")
                        },{
                            //排班列表
                            label: "医院排班",
                            isHide: true,
                            path: "/hospital/department/:hoscode",
                            element: lazyLoading("hospital/department")
                        }
                    ]
                },
                {
                    label: "商品管理",
                    path: "/product",
                    icon:<MedicineBoxOutlined />,
                    element: <Outlet/>,
                    children: [
                        {
                            // index:true,
                            path:"/product",
                            isHide:true, //是否隐藏
                            element:<Navigate to={"trademark"}/>
                        },
                        {
                            // 品牌管理
                            label:"品牌管理",
                            path:"/product/trademark",
                            element:lazyLoading("product/trademark")
                        },
                        {
                            // 平台属性管理
                            label:"平台属性管理",
                            path:"/product/attr",
                            element:lazyLoading("product/attr")
                        }
                    ]
                }
            ]
        },{
        path:"/login",
        element:(lazyLoading("Login"))
    },{
        path:"*",
        element:(lazyLoading("NotFound"))
    }
]
export  const renderMenuItem = ()=>{
    return (routes.find(v=>v.path === "/")as any).children
}


export  default  function (){
    return  useRoutes(routes)
}
